/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.sensor;

import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.frc.Robot;

/**
 *
 * @author 8349
 */
public class LimitSwitch extends DigitalInput {

    private Limiter limiter;

    public LimitSwitch(int channel, Limiter limiter) {
        super(channel);
        this.limiter = limiter;
        Robot.robot.addTicker(new Runnable() {

            private boolean limitHit;

            @Override
            public void run() {
                if (limitHit != get()) {
                    limitHit = get();
                    if (limitHit) {
                        LimitSwitch.this.limiter.limitHit();
                    } else {
                        LimitSwitch.this.limiter.limitReleased();
                    }
                }
            }
        });
    }
}
